package cn.com.ejiakanghu.web;

import cn.com.ejiakanghu.annotation.LoginUser;
import cn.com.ejiakanghu.core.exception.CheckException;
import cn.com.ejiakanghu.core.utils.RespUtil;
import cn.com.ejiakanghu.core.vo.BaseResult;
import cn.com.ejiakanghu.form.*;
import cn.com.ejiakanghu.service.*;
import cn.com.ejiakanghu.service.AliPayService;
import cn.com.ejiakanghu.service.OrderManager;
import cn.com.ejiakanghu.service.PackageService;
import cn.com.ejiakanghu.service.WxOrderService;
import cn.com.ejiakanghu.vo.*;
import org.linlinjava.litemall.core.util.IpUtil;
import org.linlinjava.litemall.db.util.OrderStatus;
import org.linlinjava.litemall.db.vo.service_order.ServiceOrderParm;
import org.linlinjava.litemall.db.vo.service_order.Serviceorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 订单相关
 *
 * @author houzb
 * @Description
 * @create 2021-03-29 19:15
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    private Logger logger = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    private WxOrderService wxOrderService;
    @Autowired
    private AliPayService aliPayService;
    @Autowired
    private OrderManager orderManager;
    @Autowired
    private PackageService packageService;
    @Autowired
    private AgeMallorderOnLineService ageMallorderOnLineService;


    /**
     * @api {get} /order/create 创建订单
     * @apiParam body 订单信息，{ cartId：xxx, addressId: xxx, couponId: xxx, message: xxx, grouponRulesId: xxx,  grouponLinkId: xxx}
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 选择商品后进行下单
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/create")
    public BaseResult createOrder(@LoginUser Integer userId, @RequestBody String body) {
        return wxOrderService.submit(userId, body);
    }

    /**
     *
     *
     * @api {post} /order/aliPay 支付宝支付
     * @apiParam body 支付宝支付参数
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 支付宝支付
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @PostMapping("aliPay")
    public BaseResult aliPay(@LoginUser Integer userId, @RequestBody String body, HttpServletRequest request) {
        return aliPayService.aliPay(userId, body);
    }

    /**
     *
     *
     * @api {post} /order/wxH5pay 微信H5支付
     * @apiParam body 微信H5支付
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 微信H5支付
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @PostMapping("wxH5pay")
    public BaseResult h5pay(@LoginUser Integer userId, @RequestBody String body, HttpServletRequest request) {
        return wxOrderService.h5pay(userId, body, request);
    }

    /**
     * 微信付款成功或失败回调接口
     * @api {post} /order/wxPayNotify 微信支付回调
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 微信付款成功或失败回调接口
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @PostMapping("wxPayNotify1")
    public Object payNotify1(HttpServletRequest request, HttpServletResponse response) {
        return wxOrderService.payNotify(request, response);
    }



    /**
     * @api {post} /order/applyReturn 申请归还设备
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 用户使用完设备后申请归还
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/applyReturn")
    public BaseResult applyReturnEqu() {
        return RespUtil.success();
    }

    /**
     * @api {post} /order/orderCancel 用户订单-用户操作-取消订单
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiParam {String} bigOrderId 大订单号
     * @apiParam {String} reason 取消订单的原因
     * @apiDescription 用户订单-用户操作-取消订单
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/orderCancel")
    public BaseResult orderCancel(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String reason) {
        return orderManager.cancel(userId, bigOrderId, reason);
    }

    /**
     * @api {post} /order/orderRemove 用户订单-用户操作-删除订单
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiParam {String} bigOrderId 大订单号
     * @apiParam {String} subOrderId 子订单号
     * @apiDescription 用户订单-用户操作-删除订单
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/orderRemove")
    public BaseResult orderRemove(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String subOrderId) {
        return orderManager.remove(userId, bigOrderId, subOrderId);
    }

    /**
     * @api {post} /order/orderList 用户订单-获取订单列表数据
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiParam {String} keyword 查询关键字
     * @apiParam {Integer} page 当前页
     * @apiParam {Integer} pageSize 页大小
     * @apiParam {String} subOrderStatus 子订单状态
     * @apiParam {Integer} bigOrderId 大订单号
     * @apiDescription 用户订单-获取订单列表数据
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/orderList")
    public BaseResult orderList(@LoginUser Integer userId,
                                @RequestParam(required = false) String keyword,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pageSize,
                                @RequestParam(required = false) String subOrderStatus,
                                @RequestParam(required = false) Integer isService,
                                @RequestParam(required = false) String bigOrderId) {
        return orderManager.list(userId, keyword, subOrderStatus, isService, page, pageSize, bigOrderId);
    }

    /**
     * @api {post} /order/subOrderDetail 用户订单-获取子订单详情
     * @apiGroup 订单
     * @apiParam {String} bigOrderId 大订单id
     * @apiParam {String} subOrderId 子订单id
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-获取子订单详情
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/subOrderDetail")
    public BaseResult subOrderDetail(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String subOrderId) {
        return orderManager.subOrderDetail(userId, bigOrderId, subOrderId);
    }

    /**
     * @api {post} /order/confirm 用户订单-用户操作-确认收货
     * @apiGroup 订单
     * @apiParam {String} bigOrderId 大订单id
     * @apiParam {String} subOrderId 子订单id
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-确认收货
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/confirm")
    public BaseResult confirm(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String subOrderId) {
        return orderManager.confirm(userId, bigOrderId, subOrderId,false);
    }

    /**
     * @api {post} /order/afterSaleSubmit 用户订单-用户操作-申请售后-订单中商品提交售后申请
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-申请售后-订单中商品提交售后申请
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/afterSaleSubmit")
    public BaseResult afterSaleSubmit(@LoginUser Integer userId, @RequestBody AfterSaleSubmitForm afterSaleSubmitForm) {
        return orderManager.afterSaleSubmit(userId, afterSaleSubmitForm);
    }

    /**
     * @api {post} /order/afterSaleCancel 订单中商品撤销售后申请
     * @apiGroup 订单
     * @apiParam {String} id 售后编号
     * @apiVersion 0.1.0
     * @apiDescription 订单中商品撤销售后申请
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/afterSaleCancel")
    public BaseResult afterSaleCancel(@LoginUser Integer userId, @RequestParam String id) {
        return orderManager.afterSaleCancel(userId, id);
    }

    /**
     * @api {post} /order/afterSaleUpdate 用户订单-用户操作-申请售后-订单中商品修改售后申请
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-申请售后-订单中商品修改售后申请
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/afterSaleUpdate")
    public BaseResult afterSaleUpdate(@LoginUser Integer userId, @RequestBody AfterSaleSubmitForm afterSaleSubmitForm) {
        return orderManager.afterSaleUpdate(userId, afterSaleSubmitForm);
    }

    /**
     * @api {post} /order/afterSaleDetail 用户订单-用户操作-申请售后-获取订单中商品的申请售后信息
     * @apiGroup 订单
     * @apiParam {String} bigOrderId 大订单id
     * @apiParam {String} subOrderId 子订单id
     * @apiParam {String} goodsId 商品ID
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-申请售后-获取订单中商品的申请售后信息
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/afterSaleDetail")
    public BaseResult afterSaleDetail(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String subOrderId, @RequestParam String goodsId) {
        return orderManager.afterSaleDetail(userId, bigOrderId, subOrderId, goodsId);
    }

    /**
     * @api {post} /order/selfExpressLogisticsNo 用户订单-用户操作-申请售后-自行寄回填写物流单号
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-申请售后-自行寄回填写物流单号
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/selfExpressLogisticsNo")
    public BaseResult selfExpressLogisticsNo(@LoginUser Integer userId, @RequestBody SelfExpressLogisticsNoForm selfExpressLogisticsNoForm) {
        return orderManager.selfExpressLogisticsNo(userId, selfExpressLogisticsNoForm);
    }

    /**
     * @api {post} /order/logisticsInfoList 用户订单-用户操作-查看物流信息列表
     * @apiGroup 订单
     * @apiParam {String} bigOrderId 大订单id
     * @apiParam {String} subOrderId 子订单id
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-查看物流信息列表
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/logisticsInfoList")
    public BaseResult logisticsInfoList(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String subOrderId) {
        return orderManager.logisticsInfoList(userId, bigOrderId, subOrderId);
    }

    /**
     * @api {post} /order/queryShipChannel 查询物流单号所属物流公司
     * @apiGroup 订单
     * @apiParam {String} expressId 快递编号
     * @apiVersion 0.1.0
     * @apiDescription 查询物流单号所属物流公司
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/queryShipChannel")
    public BaseResult queryShipChannel(@LoginUser Integer userId, @RequestParam String expressId) {
        return orderManager.queryShipChannel(userId, expressId);
    }

    /**
     * @api {post} /order/orderWarning 用户订单-用户操作-提醒发货
     * @apiGroup 订单
     * @apiParam {String} bigOrderId 大订单id
     * @apiParam {String} subOrderId 子订单id
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-提醒发货
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/orderWarning")
    public BaseResult orderWarning(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String subOrderId) {
        return orderManager.orderWarning(userId, bigOrderId, subOrderId);
    }

    /**
     * @api {post} /order/returnMethod 用户订单-用户操作-申请归还-获取租赁订单支持的归还方式
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-申请归还-获取租赁订单支持的归还方式
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/returnMethod")
    public BaseResult returnMethod(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String subOrderId) {
        return orderManager.returnMethod(userId, bigOrderId, subOrderId);
    }

    /**
     *  申请归还-验证上门取件
     * @param userId
     * @return
     */
    @RequestMapping("/checkUpdoor")
    public BaseResult checkUpdoor(@RequestBody CheckUpdoorVo checkUpdoorVo, @LoginUser Integer userId){
        return orderManager.checkUpdoor(checkUpdoorVo,userId);
    }

    /**
     * @api {post} /order/returnSelfExpress 用户订单-用户操作-申请归还-自行寄回填写物流单号
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-申请归还-自行寄回填写物流单号
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/returnSelfExpress")
    public BaseResult returnSelfExpress(@LoginUser Integer userId, @RequestBody ReturnSelfExpressForm returnSelfExpressForm) {
        BaseResult result = null;
        try {
            result = orderManager.returnSelfExpress(userId, returnSelfExpressForm);
        } catch (CheckException e) {
            logger.error("自行寄回订单异常{}",e.getResultCode());
            return RespUtil.fail(e.getResultCode());
        }
        return result;
    }

    /**
     * @api {post} /order/returnUpdoor 用户订单-用户操作-申请归还-预约上门取件
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-申请归还-预约上门取件
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/returnUpdoor")
    public BaseResult returnUpdoor(@LoginUser Integer userId, @RequestBody ReturnUpdoorForm returnUpdoorForm) {
        return orderManager.returnUpdoor(userId, returnUpdoorForm);
    }

    /**
     * @api {post} /order/cancelReturn 用户订单-用户操作-取消归还
     * @apiGroup 订单
     * @apiParam {String} bigOrderId 大订单id
     * @apiParam {String} subOrderId 子订单id
     * @apiVersion 0.1.0
     * @apiDescription 用户订单-用户操作-取消归还
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/cancelReturn")
    public BaseResult cancelReturn(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String subOrderId) {
        return orderManager.cancelReturn(userId, bigOrderId, subOrderId);
    }

    /**
     * @api {post} /order/queryOrderStatus 查询单个大订单支付状态
     * @apiGroup 订单
     * @apiParam {String} bigOrderId 大订单id
     * @apiVersion 0.1.0
     * @apiDescription 查询单个大订单支付状态
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/queryOrderStatus")
    public BaseResult queryOrderStatus(@LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam Integer queryType) {
        return orderManager.queryOrderStatus(userId, bigOrderId, queryType);
    }

    /**
     * @api {post} /order/orderSubmit 确认订单页面提交订单返回微信或支付宝支付参数
     * @apiGroup 订单
     * @apiVersion 0.1.0
     * @apiDescription 确认订单页面提交订单返回微信或支付宝支付参数
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/orderSubmit")
    public BaseResult orderSubmit(HttpServletRequest request, @LoginUser Integer userId, @RequestBody OrderSubmitForm orderSubmitForm) {
        BaseResult result = null;
        try {
            result = orderManager.orderSubmit(userId, orderSubmitForm, IpUtil.getIpAddr(request));
        } catch (CheckException e) {
            return RespUtil.fail(e.getResultCode());
        }
        return result;
    }

    /**
     * @api {post} /order/pay 用户订单-用户操作-去支付
     * @apiGroup 订单
     * @apiParam {String} bigOrderId 大订单id
     * @apiVersion 0.1.0, @RequestParam String code
     * @apiDescription 用户订单-用户操作-去支付
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/pay")
    public BaseResult pay(HttpServletRequest request, @LoginUser Integer userId, @RequestParam String bigOrderId, @RequestParam String code, @RequestParam Integer isCredit) {
        BaseResult result = null;
        try {
            result = orderManager.createWxPayOrder(userId, bigOrderId, code, isCredit, IpUtil.getIpAddr(request));
        } catch (CheckException e) {
            return RespUtil.fail(e.getResultCode());
        }
        return result;
    }

    @RequestMapping("/wxQueryOrder")
    public BaseResult wxQueryOrder(@LoginUser Integer userId, @RequestParam String bigOrderId) {
        return orderManager.wxQueryOrder(userId, bigOrderId);
    }

    @RequestMapping("/wxQueryPayOrder")
    public BaseResult wxQueryPayOrder(@LoginUser Integer userId, @RequestParam String bigOrderId) {
        return orderManager.wxQueryPayScoreOrder(userId, bigOrderId);
    }

    @PostMapping("wxPayNotify")
    public Object wxPayNotify(HttpServletRequest request, HttpServletResponse response) {
        return orderManager.payNotify(request, response);
    }

    @PostMapping("payScoreNotify")
    public Object payScoreNotify(HttpServletRequest request) {
        return orderManager.payScoreNotify(request);
    }


    /**
     *   自提扫码或手动输入确认收货
     */
    @PostMapping("/selfConfirm")
    public Object selfConfirm(SelfConfirmVo selfConfirmVo, @LoginUser Integer userId){
        return orderManager.selfConfirm(selfConfirmVo, userId);
    }

    /**
     *  配货员-获取配货订单列表
     * @return
     */
    @PostMapping("/packerOrderList")
    public Object packerOrderList(@Validated PackerOrderListVo packerOrderListVo,@LoginUser Integer userId){
        return orderManager.packerOrderList(packerOrderListVo,userId,0);
    }

    /**
     * 配货员-订单操作（拒接、接单、完成配货）
     * @return
     */
    @PostMapping("/packerOrderAction")
    public Object packerOrderAction(@RequestBody @Validated PackerOrderActionVo packerOrderActionVo,@LoginUser Integer userId){
        Object result = null;
        try {
            result = orderManager.packerOrderAction(packerOrderActionVo,userId);
        } catch (CheckException e) {
            logger.error("配货员订单操作异常{},{}",userId, e.getResultCode());
            return RespUtil.fail(e.getResultCode());
        }
        return result;
    }

    /**
     * 配送员-获取配送订单列表
     * @return
     */
    @PostMapping("/deliveryOrderList")
    public Object deliveryOrderList(@Validated PackerOrderListVo packerOrderListVo,@LoginUser Integer userId){
        return orderManager.packerOrderList(packerOrderListVo,userId,1);
    }

    /**
     * 配送员-订单操作（拒接、接单、开始配送、完成配送）
     * @return
     */
    @PostMapping("/deliveryOrderAction")
    public Object deliveryOrderAction(@RequestBody @Validated DeliveryOrderActionVo deliveryOrderActionVo,@LoginUser Integer userId){
        Object result = null;
        try {
            result = orderManager.deliveryOrderAction(deliveryOrderActionVo,userId);
        } catch (CheckException e) {
            return RespUtil.fail(e.getResultCode());
        }
        return result;
    }

    /**
     * 预约到院-用户自提
     */
    @PostMapping("/lockSelfConfirm")
    public Object lockSelfConfirm(@LoginUser Integer userId, @RequestParam String hpMac,@RequestParam String equRfid, @RequestParam String subOrderId){
        return orderManager.lockSelfConfirm(userId,hpMac,equRfid,subOrderId);
    }



    /**
     * 取回员-获取取回订单列表
     * @return
     */
    @PostMapping("/pickupOrderList")
    public Object pickupOrderList( @Validated PackerOrderListVo packerOrderListVo,@LoginUser Integer userId){
        return orderManager.packerOrderList(packerOrderListVo,userId,2);
    }



    /**
     * 取回员-订单操作（拒接、接单、开始取回、检测设备、完成取回）
     * @return
     */
    @PostMapping("/pickupOrderAction")
    public Object pickupOrderAction(@RequestBody @Validated DeliveryOrderActionVo deliveryOrderActionVo,@LoginUser Integer userId){
        Object result = null;
        try {
            result = orderManager.pickupOrderAction(deliveryOrderActionVo,userId);
        } catch (CheckException e) {
            return RespUtil.fail(e.getResultCode());
        }
        return result;
    }

    /**
     * 维护员-获取维护订单列表
     * @return
     */
    @PostMapping("/repairOrderList")
    public Object repairOrderList( @Validated PackerOrderListVo packerOrderListVo,@LoginUser Integer userId){
        return orderManager.packerOrderList(packerOrderListVo,userId,3);
    }


    /**
     * 维护员-订单操作（拒接、接单、开始维护、检测设备、完成维护）
     * @return
     */
    @PostMapping("/repairOrderAction")
    public Object repairOrderAction(@RequestBody @Validated DeliveryOrderActionVo deliveryOrderActionVo,@LoginUser Integer userId){
        Object result = null;
        try {
             result = orderManager.repairOrderAction(deliveryOrderActionVo,userId);
        } catch (CheckException e) {
            return RespUtil.fail(e.getResultCode());
        }
        return result;
    }








    //todo sunj 开发用退款接口 需要删除掉
    @PostMapping("wxRefund")
    public BaseResult wxRefund(@RequestParam String orderId) {
        return orderManager.wxRefund(orderId);
    }

    //todo sunj 开发用添加确认订单任务 需要删除掉
    @PostMapping("autoConfirm")
    public BaseResult autoConfirm(@RequestParam String orderId) {
        return orderManager.autoConfirm(orderId);
    }

    //todo sunj 开发用添加确认订单任务 需要删除掉
    @PostMapping("subpackage")
    public BaseResult subpackage(@RequestParam Integer orderId) {
        packageService.subpackage(orderId);
        return RespUtil.success();
    }


    /**
     * 取消预约
     * @param
     * @return
     */
    @PostMapping("/serviceCancelSub")
    public BaseResult serviceCancelSub(Serviceorder serviceorder){
        return ageMallorderOnLineService.cacneSubscribe(serviceorder.getServiceOrderId(), OrderStatus.CANCELED.toString());
    }

    /**
     * 修改预约时间
     * @param
     * @return
     */
    @PostMapping("/serviceEditSubDatetime")
        public BaseResult serviceEditSubDatetime(Serviceorder serviceorder){
        return ageMallorderOnLineService.serviceEditSubDatetime(serviceorder.getServiceOrderId(),serviceorder.getSubDate(),serviceorder.getSubTime());
    }

    /**
     * 增加预约服务
     * @param
     * @return
     */
    @PostMapping("/serviceCreateSub")
    public BaseResult serviceCreateSub(@RequestBody Serviceorder serviceorder,@LoginUser Integer userId){
       String wechatPhoneLen = serviceorder.getWechatPhone();
        if(wechatPhoneLen.length() > 50){
            return RespUtil.fail(6000,"微信号或手机号，不能大于50个字符！");
        }
        serviceorder.setUserId(userId);
        return ageMallorderOnLineService.serviceCreateSub(serviceorder);
    }


    /**
     * 验证手机号是否合法
     * @return
     */
    private  boolean isMobileNO(String mobile){
        if (mobile.length() != 11)
        {
            return false;
        }else{
            /**
             * 移动号段正则表达式
             */
            String pat1 = "^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
            /**
             * 联通号段正则表达式
             */
            String pat2  = "^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
            /**
             * 电信号段正则表达式
             */
            String pat3  = "^((133)|(153)|(177)|(18[0,1,9])|(149))\\d{8}$";
            /**
             * 虚拟运营商正则表达式
             */
            String pat4 = "^((170))\\d{8}|(1718)|(1719)\\d{7}$";

            Pattern pattern1 = Pattern.compile(pat1);
            Matcher match1 = pattern1.matcher(mobile);
            boolean isMatch1 = match1.matches();
            if(isMatch1){
                return true;
            }
            Pattern pattern2 = Pattern.compile(pat2);
            Matcher match2 = pattern2.matcher(mobile);
            boolean isMatch2 = match2.matches();
            if(isMatch2){
                return true;
            }
            Pattern pattern3 = Pattern.compile(pat3);
            Matcher match3 = pattern3.matcher(mobile);
            boolean isMatch3 = match3.matches();
            if(isMatch3){
                return true;
            }
            Pattern pattern4 = Pattern.compile(pat4);
            Matcher match4 = pattern4.matcher(mobile);
            boolean isMatch4 = match4.matches();
            if(isMatch4){
                return true;
            }
            return false;
        }
    }


    /**
     *医生在线咨询服务-咨询服务预约订单操作（拒接、接单、开始服务、完成服务）
     * @return
     */
    @PostMapping("/doctorServiceOrderAction")
    public BaseResult doctorServiceOrderAction(@RequestBody Serviceorder serviceorder,@LoginUser Integer userId){
        serviceorder.setUserId(userId);//医生id待修改
        return ageMallorderOnLineService.doctorServiceOrderAction(serviceorder);
    }

    /**
     * 用户在线咨询服务订单---获取在线咨询服务订单列表数据
     * @param serviceOrderParm
     * @return
     */
   @PostMapping("/serviceOrderList")
    public BaseResult serviceOrderList(ServiceOrderParm serviceOrderParm,@LoginUser Integer userId) {
        serviceOrderParm.setUserId(userId);
        BaseResult baseResult = ageMallorderOnLineService.serviceOrderList(serviceOrderParm);
        return baseResult;
    }


    /**
     * 医生在线咨询服务-获取咨询服务预约订单列表
     * @param
     * @return
     */
   @PostMapping("/doctorServiceOrderList")
    public BaseResult doctorServiceOrderList(ServiceOrderParm serviceOrderParm,@LoginUser Integer userId){
       serviceOrderParm.setUserId(userId);
       BaseResult baseResult = ageMallorderOnLineService.doctorServiceOrderList(serviceOrderParm);
        return baseResult;
    }

    /**
     * 用户在线咨询服务订单---获取在线咨询服务订单详情
     * @param serviceOrderId
     * @return
     */
    @PostMapping("/serviceOrderDetail")
    public BaseResult serviceOrderDetail(String serviceOrderId){
        ServiceOrderParm serviceOrderParm = new ServiceOrderParm();
       serviceOrderParm.setServiceOrderId(serviceOrderId);
        BaseResult baseResult = ageMallorderOnLineService.serviceOrderDetail(serviceOrderParm);
        return baseResult;
    }

    /**
     *
     * 用户在线咨询服务订单---获取在线咨询服务订单列表数据
     * @param serviceOrderParm
     * @return
     */
    @PostMapping("/serviceRecordList")
    public BaseResult serviceRecordList(ServiceOrderParm serviceOrderParm){
        return ageMallorderOnLineService.serviceRecordList(serviceOrderParm);
    }

    /**
     * 用户订单-用户操作-获取订单自提信息（注意：兼职和收货人和下单人扫描软链二维码也会调用该接口获取自提信息）
     * @return
     */
    @PostMapping("/getExtractInfo")
    public BaseResult getExtractInfo(@LoginUser Integer userId, ExtractInfoVo extractInfoVo){
        return orderManager.getExtractInfo(userId,extractInfoVo);

    }

}
